﻿<UserControl x:Class="Infrastructure.Views.PopUpView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"             
             xmlns:Helpers="clr-namespace:Infrastructure.Convertors" mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <ResourceDictionary>
            <Storyboard x:Key="PopUpOpen">
                <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="PopUpControl">
                    <EasingColorKeyFrame KeyTime="0" Value="#00000000"/>
                    <EasingColorKeyFrame KeyTime="0:0:0.5" Value="#BF000000">
                        <EasingColorKeyFrame.EasingFunction>
                            <CircleEase EasingMode="EaseOut"/>
                        </EasingColorKeyFrame.EasingFunction>
                    </EasingColorKeyFrame>
                </ColorAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="grid">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1">
                        <EasingDoubleKeyFrame.EasingFunction>
                            <CircleEase EasingMode="EaseOut"/>
                        </EasingDoubleKeyFrame.EasingFunction>
                    </EasingDoubleKeyFrame>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="grid">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1">
                        <EasingDoubleKeyFrame.EasingFunction>
                            <CircleEase EasingMode="EaseOut"/>
                        </EasingDoubleKeyFrame.EasingFunction>
                    </EasingDoubleKeyFrame>
                </DoubleAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PopUpControl">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
                    <DiscreteObjectKeyFrame KeyTime="0:0:0.5" Value="{x:Static Visibility.Visible}"/>
                </ObjectAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="PopUpControl">
                    <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="PopUpControl">
                    <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid">
                    <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="PopUpClose">
                <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="PopUpControl">
                    <EasingColorKeyFrame KeyTime="0" Value="#BF000000"/>
                    <EasingColorKeyFrame KeyTime="0:0:0.5" Value="#00000000"/>
                    <EasingColorKeyFrame KeyTime="0:0:0.6" Value="#00000000"/>
                </ColorAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="grid">
                    <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1.25">
                        <EasingDoubleKeyFrame.EasingFunction>
                            <CircleEase EasingMode="EaseOut"/>
                        </EasingDoubleKeyFrame.EasingFunction>
                    </EasingDoubleKeyFrame>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="grid">
                    <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1.25">
                        <EasingDoubleKeyFrame.EasingFunction>
                            <CircleEase EasingMode="EaseOut"/>
                        </EasingDoubleKeyFrame.EasingFunction>
                    </EasingDoubleKeyFrame>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid">
                    <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0">
                        <EasingDoubleKeyFrame.EasingFunction>
                            <CircleEase EasingMode="EaseOut"/>
                        </EasingDoubleKeyFrame.EasingFunction>
                    </EasingDoubleKeyFrame>
                </DoubleAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PopUpControl">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
                    <DiscreteObjectKeyFrame KeyTime="0:0:0.5" Value="{x:Static Visibility.Visible}"/>
                    <DiscreteObjectKeyFrame KeyTime="0:0:0.6" Value="{x:Static Visibility.Collapsed}"/>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
        </ResourceDictionary>
    </UserControl.Resources>
    <UserControl.Triggers>
        <EventTrigger RoutedEvent="UserControl.Loaded">
            <BeginStoryboard Storyboard="{StaticResource PopUpOpen}" />
        </EventTrigger>
    </UserControl.Triggers>
    <Grid x:Name="PopUpControl" Background="#BF000000" RenderTransformOrigin="0.5,0.5" Visibility="Collapsed">
        <Grid.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform/>
                <TranslateTransform/>
            </TransformGroup>
        </Grid.RenderTransform>
        <Grid x:Name="placeHolder" Visibility="{Binding IsPopupVisible, Converter={StaticResource BoolToVisibilityConverter}}" />
        <Grid x:Name="grid" Margin="100" RenderTransformOrigin="0.5,0.5">
            <Grid.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </Grid.RenderTransform>
            <Border>
                <Border Margin="0" BorderThickness="4" BorderBrush="White" Background="Black">
                    <Grid Margin="25">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="{Binding Options.Message}" VerticalAlignment="Center" TextAlignment="Center" Grid.ColumnSpan="2"/>
                        <Button Content="{Binding Options.AffirmativeText, FallbackValue=Yes}" VerticalAlignment="Top" Grid.Row="1" Height="50" Template="{DynamicResource MainButtonTemplate}" Foreground="White" 
                                FontSize="24" Margin="0,0,20,0" Command="{Binding Options.OnOptionSelected}" CommandParameter="True" IsDefault="True">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <ei:ControlStoryboardAction Storyboard="{StaticResource PopUpClose}"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Button>
                        <Button Content="{Binding Options.NegativeText, FallbackValue=No}" VerticalAlignment="Top" Grid.Row="1" Grid.Column="1" Height="50" Template="{DynamicResource MainButtonTemplate}" 
                                Foreground="White" FontSize="24" Margin="20,0,0,0" Visibility="{Binding Options.IsNegativeVisible, Converter={StaticResource BoolToVisibilityConverter}}"
                                Command="{Binding Options.OnOptionSelected}" CommandParameter="False">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <ei:ControlStoryboardAction Storyboard="{StaticResource PopUpClose}"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Button>
                    </Grid>
                </Border>
            </Border>
            <Button HorizontalAlignment="Right" VerticalAlignment="Top" Width="50" Template="{DynamicResource CircleButton}" Height="50" Margin="0,-15,-15,0">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:ControlStoryboardAction Storyboard="{StaticResource PopUpClose}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <TextBlock HorizontalAlignment="Stretch" TextWrapping="Wrap" Text="X" VerticalAlignment="Stretch" FontSize="33.333" Margin="0,-2,0,0" RenderTransformOrigin="0.5,0.5">
					<TextBlock.RenderTransform>
						<TransformGroup>
							<ScaleTransform ScaleY="0.8"/>
							<SkewTransform/>
							<RotateTransform/>
							<TranslateTransform/>
						</TransformGroup>
					</TextBlock.RenderTransform>
                </TextBlock>
            </Button>
        </Grid>
    </Grid>
</UserControl>

